<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        i {
            font-style: normal;
        }

        div {
            width: 270px;
            height: 530px;
            border: 1px solid red;
            padding: 20px 15px 0px 15px;
            margin: 0px auto;
            text-align: center;
        }

        div img {
            width: 100%;
            height: 360px;
            object-fit: cover;
        }

        .title {
            font-size: 11px;
            line-height: 11px;
            color: #6b6969;
            margin-top: 8px;
        }

        div h2 {
            font-size: 15px;
            line-height: 15px;
            margin-top: 10px;
            margin-bottom: 26px;
        }

        div span {
            font-size: 11px;
            color: #808080;
        }

        div button {
            width: 30px;
            height: 30px;
            border: 1px solid #e6e6e6;

        }

        #num {
            width: 53px;
            height: 28px;
            border: 1px solid #e6e6e6;
            padding-left: 5px;
        }

        .first {
            width: 150px;
            height: 30px;
            margin: 0px auto;
        }

        .first>span {
            height: 30px;
            line-height: 30px;
        }

        .first .fl {
            float: left;
        }

        .first button {
            float: left;
        }

        .first input {
            float: left;
        }

        div p {
            clear: both;
            margin-top: 25px;
        }
    </style>
</head>

<body>
    <div>
        <img src="../练习/2.jpg" alt="">
        <p class="title">纪梵希 小羊皮口红304</p>
        <h2>￥
            <i id="price">340</i>
        </h2>


        <h3 class="first">
            <span class="fl">数量</span>
            <button id="btn1">-</button>
            <input type="text" id="num" value="0">
            <button id="btn2">+</button>
        </h3>
        <p> 总价￥：<i id="total">0</i></p>
    </div>
    <script>
        btn2.onclick = function () {
            num.value++
            fn()
        }
        btn1.onclick = function () {
            if (num.value > 0) {
                num.value--
            }
            fn()
        }

        function fn() {
            total.innerHTML = (price.innerHTML * 1 * num.value * 1)
        }

        num.onchange = fn
    </script>
</body>

</html>